package com.starnet.yarnmonitor.yarn.conf;

import lombok.Data;
import org.apache.hadoop.fs.FileSystem;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

@ConfigurationProperties(prefix = "my.hadoop.hdfs")
@Configuration
@Data
public class HDFSConf {
    private String fileAbsolutePath;
    private String fileRelativePath;
    private String logPath;
    private String defaultFS;
    private String autoJarPath;
    @Bean
    public FileSystem myHDFS(){
        org.apache.hadoop.conf.Configuration conf = null;
        FileSystem fs = null;
        System.setProperty("HADOOP_USER_NAME", "root");
        conf = new org.apache.hadoop.conf.Configuration();
        conf.set("fs.defaultFS", defaultFS);
        try {
            fs = FileSystem.get(conf);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return fs;
    }
}
